package test.serverframe.armc.server.manager.dao.mapper;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import test.serverframe.armc.server.manager.domain.Tag;

import java.util.Map;

/**
 * @author UaenaSA
 */
public class TagSqlProvider {

    public String insertSelective(Tag record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("tb_ssgp_tag");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=VARCHAR}");
        }
        
        if (record.getTag() != null) {
            sql.VALUES("tag", "#{tag,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Tag record) {
        SQL sql = new SQL();
        sql.UPDATE("tb_ssgp_tag");
        
        if (record.getTag() != null) {
            sql.SET("tag = #{tag,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("id = #{id,jdbcType=VARCHAR}");
        
        return sql.toString();
    }
    public String selectByPage(Map<String, Object> params) {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT id,tag " +
                " FROM tb_ssgp_tag ");
        Object name = params.get("tagName");
        if (name != null && StringUtils.isNotBlank(name.toString())) {
            sql.append(" where tag like '%" + name.toString() + "%'");
        }
        sql.append(" ORDER BY tag ");
        return sql.toString();
    }
}